<!DOCTYPE html>
<html>
<?php require_once "app/conn.php"; ?>
	<head>
		<meta charset="utf-8">
		<link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
		<title>图书管理系统</title>
		<style type="text/css">
			* {
				margin: 0px;
				padding: 0px;
			}
			
			.all {
				width: 100%;
			}
			
			.top {
				width: 100%;
				height: 70px;
				background-color: black;
				color: white;
			}
			
			.top h1 {
				text-align: center;
				width: 70%;
				padding-top: 10px;
				float: left;
				padding-left: 30px;
			}
			
			.middles {
				width: 100%;
			}
			
			.left {
				width: 15%;
				height: 600px;
				background-color: #888888;
				float: left;
			}
			
			.left ul li {
				width: 100%;
				text-align: center;
				line-height: 50px;
			}
			
			.left ul li:hover {
				background-color: #C0C0C0;
			}
			
			.bottom {
				height: 50px;
				width: 100%;
				background-color: #444444;
				position: fixed;
				bottom: 0px;
			}
			
			a {
				text-decoration: none;
				display: block;
			}
			
			.right {
				float: left;
				width: 85%;
				height: 600px;
			}
			
			.bottom p {
				width: 100%;
				text-align: center;
				color: white;
				padding-top: 10px;
			}
			
			.left h2 {
				width: 100%;
				height: 60px;
				text-align: center;
				line-height: 60px;
			}
			
			.bar1 {
				background: #A3D0C3;
			}
			
			.bar1 input {
				border: 2px solid #7BA7AB;
				border-radius: 5px;
				background: #F9F0DA;
				color: #9E9C9C;
				width: 300px;
				height: 33px;
			}
			
			.bar1 button {
				width: 33px;
				height: 33px;
				background: #7BA7AB;
				border-radius: 0 5px 5px 0;
			}
			
			.bar1 button:before {
				content: "\f002";
				font-family: FontAwesome;
				font-size: 16px;
				color: #F9F0DA;
			}
			.search{
				width: 80%;
				background-color: #C7DDEF;
				margin-left: auto;
				margin-right: auto;
				border-radius: 10px;
				padding: 10px;
				padding-left: 100px;
				margin-top: 10px;
			}
			
			.book-info{
				width: 90%;
				height: 95px;
				background-color: #FFCC33;
				margin-left: auto;
				margin-right: auto;
				margin-top: 20px;
				border-radius: 5px;
			}
			.book-info h3,.book-info p{
				line-height: 30px;
				padding-left: 10px;
				padding-right: 10px;
			}
		</style>
	</head>

	<body>
		<div class="all">
			<div class="top">
				<h1>图书管理系统</h1>
				<p>
					<?php 
						if(isset($_COOKIE["user"]))
						{
							echo '<p style="line-height:70px;float:right;padding-right:30px;">欢迎用户<lable>'.$_COOKIE["user"].'</lable></p>';
						}else
						{
							echo '<a href="/login.php" style="float:right;line-height:70px;padding-right:30px">请登录</a>';
						}
						
					?>
				</p>
				<div style="clear: both;"></div>
				</div>
			<div class="middles">
				<div class="left">
					<h2>图书分类</h2>
					<HR style="FILTER: alpha(opacity=100,finishopacity=0,style=3)" width="99%" color=#000000 SIZE=3>
					<ul>
						<?php 
						$sql1="select * from classes";
						$result1 = $conn->query($sql1);
						while($row = mysqli_fetch_assoc( $result1 )){
						?>
						<li>
							<a href="
								<?php
								$urls='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
								if(!empty($_GET['search']))
								{
									$urls=$urls.'?search='.$_GET['search'];
									$urls=$urls.'&'.'classes='.$row['类别'];
								}else{
									$urls=$urls.'?'.'classes='.$row['类别'];
								}
								
								echo $urls;
								?>
								"><?php echo $row["类别"]?></a>
						</li>
						<?php }?>
					</ul>
				</div>
				<div class="right">
					<div class="search bar1">
						<form action="index.php" method="get">
							<input type="text" placeholder="请输入您要搜索的内容..." name="search">
							<button type="submit"></button>
						</form>
						<?php 
							$ziju="";
							if(!empty($_GET['search']))
							{
								$ziju=" where 书名 like '%".$_GET['search']."%'";
							}
							 ?>
							 <div style="clear: both;"></div>
							 <p style="float: left;">
							 <?php 
							 	if(!empty($_GET['search']))
							 	{
							 		echo "您正在查找 '".$_GET['search']."' 相关图书";
							 		?>
							 	</p>
							 		<?php
							 		$urls='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
							 		echo '<a href="'.$urls.'" style="float: left;padding-left:5px;">取消搜索内容</a>';
							 	}
							 	?>
							 	
							 <div style="clear: both;"></div>
							 
					</div>
					<?php 
						if(!empty($_GET['classes']))
						{
							if(!empty($ziju))
							{
								$ziju=$ziju." and 类型='".$_GET['classes']."'";
							}else{
								$ziju=" where 类型='".$_GET['classes']."'";
							}
						}
						$sql="select * from book".$ziju;
						$result = $conn->query($sql);
						while($row = mysqli_fetch_assoc( $result )){
						?>
					<div class="book-info">
						<h3 style="float: left;"><?PHP echo $row["书名"]?></h3>
						<p style="float: right;"><?PHP echo "编号：".$row["id"]?></p>
						<?php 
							if(isset($_COOKIE))
							{
								$sql_num="select * from book where id=".$row["id"];
								$result_num = $conn->query($sql_num);
								$row_num=mysqli_fetch_assoc( $result_num );
								if($row_num['数量']>0)
								{
								echo '<a href="app/jie.php?userid='.$_COOKIE['user_id'].'&bookid='.$row["id"].'" style="float:right;padding:3px;">借阅</a>';
								}
							}
							?>
						
						<HR style="FILTER: alpha(opacity=50,finishopacity=0,style=3)" width="99.5%" color=#000000 SIZE=1>
						<div style="clear: both;"></div>
						<p style="float: left;"><?PHP echo "出版社：".$row["出版社"]?></p>
						<p style="float: right;"><?PHP echo "出版日期：".$row["出版日期"]?></p>
						<div style="clear: both;"></div>
						<p style="float: left;"><?PHP echo "作者：".$row["作者"]?></p>
						<p style="float: left; padding-left: 30px;"><?PHP echo "类别：".$row["类型"]?></p>
						<p style="float: right;"><?PHP echo "数量：".$row["数量"]?></p>
						<div style="clear: both;"></div>
					</div>
					<?php 
						}
						$conn->close();
						?>
						<div style="height: 80px;width: 1px;"></div>
				</div>
			</div>
			<div class="bottom">
				<p>MADE BY swust 3
						</p>
			</div>
		</div>
	</body>

</html>